/**
 * Created by wangmeng on 2018/8/15.
 */
var cellRows = [];    //设置完成的信息，用于界面间的传值
$(function () {
    var cellRow = getGlobalVariable("cellRow");
    var columnName = JSON.parse(cellRow)[0].columnName;
    var dataSource = JSON.parse(cellRow)[0].dataSource;
    var excelColumn = JSON.parse(cellRow)[0].excelColumn;
    var excelColumnNo = JSON.parse(cellRow)[0].excelColumnNo;
    var mapperTable = JSON.parse(cellRow)[0].mapperTable;
    var mapperField = JSON.parse(cellRow)[0].mapperField;
    var fetchField = JSON.parse(cellRow)[0].fetchField;
    var condition = JSON.parse(cellRow)[0].condition;
    $('#columnName').val(columnName);
    $('#dataSource').val(dataSource);
    $('#excelColumn').val(excelColumn);
    $('#excelColumnNo').val(excelColumnNo);
    $('#mapperTable').val(mapperTable);
    $('#mapperField').val(mapperField);
    $('#fetchField').val(fetchField);
    $('#condition').val(condition);
});

//保存增加的数据
function submit_Add() {
    var dataSource = $("#dataSource").val();
    var excelColumn = $("#excelColumn").val();
    var excelColumnNo = $("#excelColumnNo").val();
    var mapperTable = $("#mapperTable").val();
    var mapperField = $("#mapperField").val();
    var fetchField = $("#fetchField").val();
    if(dataSource == "1"){
        if(excelColumn == ""){
            $.messager.alert("提示", "请填写excel列名！", "info");
            return;
        }
        if(excelColumnNo == ""){
            $.messager.alert("提示", "请填写excel列号！", "info");
            return;
        }
    }else if(dataSource == "2"){
        if(excelColumn == ""){
            $.messager.alert("提示", "请填写excel列名！", "info");
            return;
        }
        if(excelColumnNo == ""){
            $.messager.alert("提示", "请填写excel列号！", "info");
            return;
        }
        if(mapperTable == ""){
            $.messager.alert("提示", "请填写映射表名！", "info");
            return;
        }
        if(mapperField == ""){
            $.messager.alert("提示", "请填写映射字段！", "info");
            return;
        }
        if(fetchField == ""){
            $.messager.alert("提示", "请填写取数字段！", "info");
            return;
        }
    }
    //新增行
    var newRow = new Object();
    newRow.columnName = $("#columnName").val();
    newRow.dataSource = $("#dataSource").val();
    newRow.excelColumn = $("#excelColumn").val();
    newRow.excelColumnNo = $("#excelColumnNo").val();
    newRow.mapperTable = $("#mapperTable").val();
    newRow.mapperField = $("#mapperField").val();
    newRow.fetchField = $("#fetchField").val();
    newRow.condition = $("#condition").val();
    cellRows.push(newRow);
    setGlobalVariable("cellRow",JSON.stringify(cellRows));
    closeLayer();
}